import store from "store/store"
import { whiteList } from "@/util/config"
import {Message} from "element-ui";

export function defined(router){
  let flag = true
  router.beforeEach(async (to,from,next)=>{
    // 刷新时，自动登录
    if(flag){
      flag = false
      await store.dispatch("autoLogin",to)
    }
    // 判断是否登录
    if(Object.keys(store.state.user.userInfo).length<1){
      // 如果未登录
      let name = to.path.split("/")[1]
      console.log(name);
      if(!whiteList.includes(name)){
        next()
      }else{
        //清除前面的提醒!!!
        Message.closeAll();
        //提醒
        // Message.error("您还未登录");
        Message({
            message:"您还未登录",
            type:"error"
        })
      }
    }else{
      next()
    }

  })

  router.beforeResolve((to,from,next)=>{
    next()
  })

  router.afterEach(()=>{
    
  })
}